﻿/*
   Copyright 2012 University of Southampton

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace uk.ac.soton.ses
{
    class ExperimentDataFileMetadataContainerXML : ExperimentDataFileMetadataContainer
    {
        private ExperimentMetadataContainerXML ParentXMLContainer { get { return base._parentExperiment as ExperimentMetadataContainerXML; } }

        public ExperimentDataFileMetadataContainerXML(ExperimentDataFileBO experimentDataFile, ExperimentMetadataContainerXML parentExperimentMetadata)
            :base(experimentDataFile,parentExperimentMetadata)
        {
        }

        override public void RenameExperimentDataFile(string newName, string newExperimentBasePath)
        {
            this.ParentXMLContainer.SaveToHistory(this.ExperimentDataFile, ExperimentMetadataAction.Updated);

            //Note, we don't update the metadata itself. This is because changes happen to the business objects which are then saved to the metadata with base.SaveChanges()
            base.RenameExperimentDataFile(newName, newExperimentBasePath);
        }

        override public void DeleteExperimentDataFile()
        {
            this.ParentXMLContainer.SaveToHistory(this.ExperimentDataFile, ExperimentMetadataAction.Deleted);

            //Note, we don't update the metadata itself. This is because changes happen to the business objects which are then saved to the metadata with base.SaveChanges()
            base.DeleteExperimentDataFile();
        }

        public override void UpdateExperimentDataFile(ExperimentDataFileBO updatedExperiment)
        {
            this.ParentXMLContainer.SaveToHistory(this.ExperimentDataFile, ExperimentMetadataAction.Updated);
            base.UpdateExperimentDataFile(updatedExperiment);
        }

        public override ExperimentDataFileMetadataContainer Copy()
        {
            ExperimentDataFileMetadataContainerXML newContainer = new ExperimentDataFileMetadataContainerXML(base._experimentDataFile, (ExperimentMetadataContainerXML)base._parentExperiment);
            return newContainer;
        }
    }
}
